import 'package:flutter/material.dart';
import '../widgets/platform/adaptive_card.dart';

/// 团队协作动态组件
class TeamCollaboration extends StatelessWidget {
  final List<CollaborationActivity> activities;
  final String? title;

  const TeamCollaboration({
    super.key,
    required this.activities,
    this.title,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        if (title != null) ...[
          Text(
            title!,
            style: Theme.of(context).textTheme.titleLarge,
          ),
          const SizedBox(height: 16),
        ],
        AdaptiveCard(
          child: ListView.builder(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemCount: activities.length,
            itemBuilder: (context, index) {
              final activity = activities[index];
              return _buildActivityItem(
                context,
                activity,
                index != activities.length - 1,
              );
            },
          ),
        ),
      ],
    );
  }

  /// 构建活动项
  Widget _buildActivityItem(
    BuildContext context,
    CollaborationActivity activity,
    bool showDivider,
  ) {
    return Column(
      children: [
        ListTile(
          leading: CircleAvatar(
            radius: 16,
            backgroundColor: Colors.grey[200],
            child: Text(
              activity.user.substring(0, 1),
              style: const TextStyle(
                color: Colors.grey,
                fontSize: 12,
              ),
            ),
          ),
          title: Text.rich(
            TextSpan(
              children: [
                TextSpan(
                  text: activity.user,
                  style: const TextStyle(fontWeight: FontWeight.bold),
                ),
                TextSpan(
                  text: ' ${activity.action}',
                  style: const TextStyle(fontWeight: FontWeight.normal),
                ),
              ],
            ),
            style: const TextStyle(fontSize: 14),
          ),
          subtitle: Text(
            activity.time,
            style: const TextStyle(
              fontSize: 12,
              color: Colors.grey,
            ),
          ),
        ),
        if (showDivider) const Divider(height: 1),
      ],
    );
  }
}

/// 协作活动数据模型
class CollaborationActivity {
  final String user;
  final String action;
  final String time;

  CollaborationActivity({
    required this.user,
    required this.action,
    required this.time,
  });
}